﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Nox.Amuse.ViewModel;
using System.ComponentModel;
using Nox.Amuse.View;

namespace Nox.Amuse
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        bool FirstDisplay = true;

        public MainWindow()
        {
            InitializeComponent();

            this.DataContext = new MainWindowViewModel();
            this.Activated += new EventHandler(MainWindow_Activated);
            this.Closing += new CancelEventHandler(MainWindow_Closing);
        }

        void MainWindow_Closing(object sender, CancelEventArgs e)
        {
            if (!App.IsReadyToExit) // Is the closing request came from this View rather than Application Shutdown...
            {
                App.Messenger.NotifyColleagues(Messages.ExitRequest);
                e.Cancel = !App.IsReadyToExit;
            }
        }

        void MainWindow_Activated(object sender, EventArgs e)
        {
            if (FirstDisplay)
            {
                this.CorrectWindowPosition();
                FirstDisplay = false;
            }
            App.Messenger.NotifyColleagues(Messages.MainWindowActivated);
        }

    }
}
